package toanstt.com.ads;


import toanstt.com.MatchUp.ButtonCenter;
import toanstt.com.MatchUp.MainActivity;
import toanstt.com.MatchUp.T;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.google.ads.searchads.SearchAdRequest;

import android.R;
import android.R.string;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.net.Uri;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

public class Ads 
{
	 public static AdView adView;
	 public static RelativeLayout.LayoutParams params;
	 Bitmap bitmap;
	 ButtonCenter button;
	int height;
	int width;
	boolean isdraw=false;
	boolean turnoff=false;
	int temp_x,temp_y;
	
	int action, actionCode;
	float TIME_DONE = 10000.0f;
	long BACK_TIME;
	long CURRENT_TIME;
	int THRESH = 320;
	public Ads(AdView adView1)
	{
		
		adView = adView1;
		
		bitmap = T.loadImageFromAsset("butads.png");
		
		isdraw = false;
		
		BACK_TIME = CURRENT_TIME = System.currentTimeMillis();
				
				
		//adView.setTop(100);
		
		//button = new Button(bitmap, 800 - , y1, scale2)
	}
	public void Draw(Canvas canvas)
	{
		
		//Log.d("Ads","" + MainActivity.adView.getWidth());
	/*	if(MainActivity.adView.getWidth() > THRESH)
		{
			Log.d("Ads222","" + MainActivity.adView.getWidth());
			MainActivity.adsParams.setMargins(100, 0, 36, 100);
			
		}*/
		
		if(turnoff == false)
		{
		
			if(isdraw == false)
			{
				width = MainActivity.adView.getWidth();
				
				if(width > THRESH)
				{
					
					height = adView.getHeight();
					float scale = height*1.0f/80.0f;
					isdraw = true;
					if(T.ISHORIZONTAL)
						button = new ButtonCenter(bitmap, T.DISPLAY_WIDTH - 18  - width,T.DISPLAY_HEIGHT -  18);
					else
						button = new ButtonCenter(bitmap, T.DISPLAY_WIDTH - 18 ,T.DISPLAY_HEIGHT -  18);
					//button = new ButtonCenter(bitmap, T.DISPLAY_WIDTH - 18 , T.DISPLAY_HEIGHT - 18);
				}
				
			}
		}
		
		if(isdraw == true)
		{
			button.Draw2(canvas);
		}
		
		
	}
	int i =0;
	boolean temp;
	public boolean touch(MotionEvent mo)
	{
		
		if(isdraw == false)
			return false;
		
		action = mo.getAction();
		actionCode = action & MotionEvent.ACTION_MASK;
		temp_x = (int)mo.getX();
		temp_y = (int)mo.getY();
		if(temp  = button.Kick(mo))
		{
			turnoff = true;
			isdraw = false;
			
			adView.setEnabled(false);
			adView.setVisibility(View.GONE);
			
			
			button.anpla = 255;
			return true;
		}
		
		if(actionCode == MotionEvent.ACTION_UP)
		{
			button.anpla = 255;
			
		}
		if(button.anpla == 255)
			return false;
		return true;
		
	}
	public void setTurnON()
	{
		turnoff = false;
		adView.setEnabled(true);
		adView.setVisibility(View.VISIBLE);
	}
	
}
